package demo.command;

import java.util.ArrayList;
import java.util.List;

/**
 * 模拟内存泄露
 *
 * @author zheng9feng
 * @date 2021/5/10 14:27
 */
public class MemoryLeakDemo {
	
	
	public static void fillHeap(int num) throws InterruptedException {
		List<OOMobject> leapList = new ArrayList<>();
		for (int i = 0; i < num; i++) {
			//稍作延时,令监视曲线的变化更加明显
			Thread.sleep(500);
			leapList.add(new OOMobject());
			System.out.println("Hello World---i:" + i);
		}
	}
	
	public static void main(String[] args) throws Exception {
		fillHeap(10000);
	}
	
	static class OOMobject {
		public static final byte[] _10MB = new byte[10 * 1024 * 1024];
	}
}
